function initCategories()
{
    category = $('span.category');
    
    category.each(function() {
        
        percent = parseInt($(this).children().attr('class'));
        max_size = 30;
        size = percent * max_size / 100;    
        start_opacity = 0.3 + parseFloat(percent / 300);
        size += 10;

        rand_string = size + 'px';

        $(this).css({
            'fontSize': rand_string,
            'opacity': start_opacity
        });

        $(this).children()
               .removeClass($(this).children().attr('class'))
               .addClass(String(start_opacity));
               
        $(this).hover(function() {

           $(this).stop().animate({
               opacity: '1.0'
           }, 200);
        }, function() {
            
           $(this).stop().animate({
               opacity: parseFloat($(this).children().attr('class'))
           }, 600);
        });
    });
}

function initChapterBar()
{    
    chapter = $('.chapters li');

    chapter.each(function() {  
        // Groesse anpassen
        $(this).css('width', '100%');
        size = $(this).children('span').attr('class');
        newwidth = parseInt($(this).width());
        newwidth = (newwidth / size) - 11;
        $(this).css('width', newwidth);
    });
}


function initTutorialBox() {
    
    box = $('div.description_box');
    time = 300;
    
    box.each(function() {
        toparea_height = $(this).height() - $(this).children('.chapters').height();
        transparent_height = $(this).children('.topcontent').children('.transparent').height();
        
        topcontent_padding = toparea_height - transparent_height;
        $(this).children('.topcontent').css('paddingTop', topcontent_padding);
        
        $(this).hover(function() {
            
            $(this).children('.topcontent').stop(true, true).animate({
                paddingTop: "0"
            }, time, function() {
                $(this).children('.transparent').children('.autorinfo').css({
                    'opacity': '0',
                    'display': 'block'
                }).stop(true, true).animate({
                    opacity:"1"
                }, time);
            });
            
            $(this).children('.topcontent').children('.transparent').stop(true, true).animate({
                height: topcontent_padding + transparent_height
            }, time);
            
             $(this).children('.topcontent').children('.background-categories').stop(true, true).animate({
                opacity: "0.1"
            }, time);
        }, function() {
            $(this).children('.topcontent').children('.transparent').children('.autorinfo').animate({
                opacity: "0"
            }, 50, function() {
                $(this).css('display', 'none');        
            });    
            $(this).children('.topcontent').stop(true, true).animate({
                paddingTop: topcontent_padding
            }, time);
            
            $(this).children('.topcontent').children('.transparent').stop(true, true).animate({
                height: transparent_height
            }, time);
            
             $(this).children('.topcontent').children('.background-categories').stop(true, true).animate({
                opacity: "0.3"
            }, time);
        });       
        
    });
    
    calculatePositions();
}



/**
 * Initialisiert Javascript, JQuery etc.
 * 
 * @author      Miguel Gonzalez
 * @since       25-10-2011
 * @version     1.0
 */
function init() {
    
    // Bilder vorladen
    preload();
    
    // Cakelink faden
    cakelink = $('#cakelink');
    cakelink.css('opacity', 0.7);
    
    cakelink.hover(function() {
        $(this).stop(true, true).animate({ opacity: "1.0" }, 120);
    }, function() {
        $(this).stop(true, true).animate({ opacity: "0.7" }, 400);
    });

    // Eingabefelder initialisieren
    initInput(); 
    // Dropdown-Menues initialisieren
    initDropdown();  
    initCategories();
    registerElements();
    initTutorialBox();
    
    $(window).resize(function() {
        calculatePositions();
    });
    
}


function setContent(id, from) {
    
    from_element = $('#' + from);
    element = $('#' + id);
    time = 500;
    
    if (from_element.html() != element.html())
    {
        element.stop(true, true).animate({
            opacity: "0.0"
        }, time, function() {
            html = from_element.html();
            $(html).appendTo('#' + id);
            element.html(html);

        }).animate({
            opacity: "1.0"
        }, time);
        
        
        
        
    }
}
